import instance from "@/main";
import quotationDict from "@/dict/quotation";

export default function btnJudge(flag, row) {
  let res = false;
  // // 是否超管
  // let isSuperAdmin = function() {
  //   return instance.$isSuperAdmin(
  //     instance.$store.state.user.userData &&
  //       instance.$store.state.user.userData.userState
  //   );
  // };
  // 是否管理员以上
  let isAdmin = function() {
    return instance.$store.state.user.isAdmin;
  };
  // 是否发布人
  let isCreatedUser = function() {
    return (
      row.userId ===
      (instance.$store.state.user.userData &&
        instance.$store.state.user.userData.userId)
    );
  };
  switch (flag) {
    // 同意：待审核、管理员
    case "agree":
      res =
        row.quotationType === quotationDict.status.pending.value && isAdmin();
      break;
    // 拒绝：待审核、管理员
    case "reject":
      res =
        row.quotationType === quotationDict.status.pending.value && isAdmin();
      break;
    // 上架：已下架、管理员、发布人
    case "added":
      res =
        row.quotationType === quotationDict.status.unshelve.value &&
        (isAdmin() || isCreatedUser());
      break;
    // 下架：上架中、管理员、发布人
    case "unshelve":
      res =
        row.quotationType === quotationDict.status.onsale.value &&
        (isAdmin() || isCreatedUser());
      break;
    // 编辑：已下架、已拒绝、管理员、发布人
    //      待审核、发布人
    case "edit":
      res =
        ((row.quotationType === quotationDict.status.unshelve.value ||
          row.quotationType === quotationDict.status.denied.value) &&
          (isAdmin() || isCreatedUser())) ||
        (row.quotationType === quotationDict.status.denied.value &&
          (isCreatedUser() || !isAdmin())) ||
        (row.quotationType === quotationDict.status.pending.value &&
          isCreatedUser());
      break;
    // 删除：已下架、管理员、发布人
    case "del":
      res =
        (row.quotationType === quotationDict.status.unshelve.value ||
          row.quotationType === quotationDict.status.denied.value) &&
        (isAdmin() || isCreatedUser());
      break;
    // 调整库存：已下架、管理员、发布人
    case "updateStock":
      res =
        row.quotationType === quotationDict.status.unshelve.value &&
        (isAdmin() || isCreatedUser());
      break;
    // 调整升贴水：已下架、管理员、发布人
    case "updatePremium":
      res =
        row.priceType === 1 &&
        row.quotationType === quotationDict.status.unshelve.value &&
        (isAdmin() || isCreatedUser());
      break;
    // 调整价格：已下架、管理员、发布人
    case "updatePrice":
      res =
        row.priceType === 2 &&
        row.quotationType === quotationDict.status.unshelve.value &&
        (isAdmin() || isCreatedUser());
      break;
    // 导出剩余数：已下架、管理员、发布人
    case "residue":
      res =
        row.quotationType === quotationDict.status.unshelve.value &&
        (isAdmin() || isCreatedUser());
      break;
    default:
      break;
  }
  return res;
}
